CSharpTest.Net
SHA1(Byte[]) Method
See Also  Example Send Feedback Download Help File
CSharpTest.Net.Library Assembly > CSharpTest.Net.Crypto Namespace > Hash Class > SHA1 Method : SHA1(Byte[]) Method

bytes

Glossary Item Box

Computes an SHA1 hash

Syntax

Visual Basic (Declaration) 
Public Overloads Shared Function SHA1( _
   ByVal bytes() As Byte _
) As Hash
C# 
public static Hash SHA1( 
   byte[] bytes
)

Parameters

bytes

Example

Library/Library.Test/TestHash.cs

C#Copy Code
Random r = new Random();
byte[] a = new byte[10], b = new byte[10];
r.NextBytes(a);
r.NextBytes(b);

Hash h1 = Hash.SHA256(a);
Hash h2 = Hash.SHA1(b);
Hash h3 = h1.Combine(h2);

Assert.AreEqual(h3.ToString(), Hash.SHA256(
    new CombinedStream(
        new MemoryStream(h1.ToArray()),
        new MemoryStream(Hash.SHA256(h2.ToArray()).ToArray()) //the dissimilar hash is first made the same length
        )).ToString());
VB.NETCopy Code
Dim r As New Random()
Dim a As Byte() = New Byte(10) {}, b As Byte() = New Byte(10) {}
r.NextBytes(a)
r.NextBytes(b)

Dim h1 As Hash = Hash.SHA256(a)
Dim h2 As Hash = Hash.SHA1(b)
Dim h3 As Hash = h1.Combine(h2)

'the dissimilar hash is first made the same length
Assert.AreEqual(h3.ToString(), Hash.SHA256(New CombinedStream(New MemoryStream(h1.ToArray()), New MemoryStream(Hash.SHA256(h2.ToArray()).ToArray()))).ToString())

Requirements

Target Platforms: Windows XP, Windows Server 2003, Windows Vista, Windows Server 2008, Windows 7

See Also

Generated with Document! X 2011 by Innovasys